package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.ObjectiveDAO;
import com.zerosky.crm.po.Objective;
import com.zerosky.crm.service.ObjectiveService;
import com.zerosky.crm.util.PageInfo;

/**
 * Invite业务逻辑实现类
 * 
 * @author zhouzhengxiang;
 * @since 2017-07-13
 *
 */
@Service(value="objectiveService")
public class ObjectiveServiceImpl implements ObjectiveService {
	@Autowired
	private ObjectiveDAO objectiveDAO; // Invite数据接口

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Objective getInvite(Map<String, Object> map) {
		Objective objective = objectiveDAO.getInvite(map);
		return objective;
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int addInvite(Objective invite) {
		return objectiveDAO.addInvite(invite);
	}

	@Override
	public PageInfo<Objective> getObjectiveStatisticsByPersonal(Map<String, Object> map) {
		PageInfo<Objective> page = new PageInfo<Objective>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));
		// 写入数据
		map.put("pageNo", begin);
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByPersonal(map);
		page.setList(list);
		int count = objectiveDAO.getObjectiveStatisticsByPersonalCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	public PageInfo<Objective> getObjectiveStatisticsByTeam(Map<String, Object> map) {
		PageInfo<Objective> page = new PageInfo<Objective>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));
		// 写入数据
		map.put("pageNo", begin);
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByTeam(map);
		page.setList(list);
		int count = objectiveDAO.getObjectiveStatisticsByTeamCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	public PageInfo<Objective> getObjectiveStatisticsByBranch(Map<String, Object> map) {
		PageInfo<Objective> page = new PageInfo<Objective>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));
		// 写入数据
		map.put("pageNo", begin);
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByBranch(map);
		page.setList(list);
		int count = objectiveDAO.getObjectiveStatisticsByBranchCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	public PageInfo<Objective> getObjectiveStatisticsByDept(Map<String, Object> map) {
		PageInfo<Objective> page = new PageInfo<Objective>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));
		// 写入数据
		map.put("pageNo", begin);
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByDept(map);
		page.setList(list);
		int count = objectiveDAO.getObjectiveStatisticsByDeptCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	public Objective getDept(Map<String, Object> map) {
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByDept(map);
		if (list.size()>0) {
			Objective ob = list.get(0);
			return ob;
		} else {
			return null;
		}

	}

	@Override
	public Objective getBranch(Map<String, Object> map) {
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByBranch(map);
		if (list.size()>0) {
			Objective ob = list.get(0);
			return ob;
		} else {
			return null;
		}
	}

	@Override
	public Objective getTeam(Map<String, Object> map) {
		List<Objective> list = objectiveDAO.getObjectiveStatisticsByTeam(map);
		if (list.size()>0) {
			Objective ob = list.get(0);
			return ob;
		} else {
			return null;
		}
	}

}
